/**
 * 人才库-加入/移出黑名单
 */
import React, { memo, useEffect, useState } from 'react';
import { withRouter } from 'umi';
import AuthComponent from '@/utils/auth/AuthComponent';
import { Icon } from '../../components';
import TalentsBlackListModal from './TalentsBlackListModal';

function TalentsBlackListOperate({ resumeId, operateType, onRefresh, button = false, ...rest }) {
    const [blackListModalVisible, setBlackListModalVisible] = useState(false);
    const [title, setTitle] = useState('');
    useEffect(() => {
        setTitle(operateType === 'add' ? '加入黑名单' : '移出黑名单');
    }, [operateType]);
    return (
        <AuthComponent code={operateType === 'add' ? 'office:recruitment:talentsManagement:addBlackList' : 'office:recruitment:talentsManagement:removeBlackList'}>
            <Icon
                type={operateType === 'add' ? 'listfunction_addtoblacklist_icon_default' : 'listfunction_removefromblacklist_icon_default'}
                title={title}
                button={button}
                onClick={() => {
                    setBlackListModalVisible(true);
                }} />
            <TalentsBlackListModal
                title={title}
                operateType={operateType}
                visible={blackListModalVisible}
                onCancel={() => { setBlackListModalVisible(false) }}
                onOk={() => {
                    setBlackListModalVisible(false);
                    onRefresh();
                }}
                {...rest}
            />
        </AuthComponent>
    );
}
export default withRouter(memo(TalentsBlackListOperate));
